﻿@{
    ViewBag.Title = "选择函数";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script src="../../Scripts/date.format.js" type="text/javascript"></script>
    <script type="text/javascript">
        var retArr = new Array();
        var ExpIDs = new Array();
        var selectCount = -1;
        var opts = {
            rows: 10,
            height: 450,
            url: "",
            para: {},
            idField: "Guid",
            checkbox: true,
            columns: [
                     { field: 'FunName', title: '函数名称', width: 30, sortable: true },
                    { field: 'ParamCount', title: '参数数量', width: 6, sortable: true },
                    { field: 'FunType', title: '函数类型', width: 8, sortable: true,
                        formatter: function (value, rowData, rowIndex) {
                            var format = "";
                            if (value == 1)
                                format = "表值函数";
                            else if (value == 2)
                                format = "标量值函数";
                            else if (value == 3)
                                format = "聚合函数";
                            else if (value == 4)
                                format = "系统函数";
                            return format;
                        }
                    },
                    { field: 'Description', title: '函数说明', width: 48, sortable: true }
                    ],
            OnChickRow: function (value, rowData, rowIndex) {
                var s = true;
                if (selectCount > -1 && ExpIDs.length >= selectCount) {
                    alert("只可选择 " + selectCount + " 个，请检查选择项。");
                    s = false;
                    return false;
                }
                if (s) {
                    $("#sel_content").append("<span class='s1 s1" + value + "'><a title='" + rowData.Description + "'>" + rowData.FunName + "</a><span class='s2 s2" + value + "''>&nbsp;X&nbsp;</span></span>");

                    $(".s2" + value).bind("click", function () {
                        $(".s1" + value).remove();
                        $(".s2" + value).remove();
                        for (var j = 0; j < retArr.length; j++) {
                            if (retArr[j].Guid == value) {
                                retArr.removeAt(j);
                            }
                        }
                        ExpIDs.removeValue(value);
                        opts.para["ExpIDs"] = ExpIDs.join(",");
                        initTable("DataGrid", opts);
                    });
                    retArr.push(rowData);
                    ExpIDs.push(value);
                    opts.para["ExpIDs"] = ExpIDs.join(",");
                    initTable("DataGrid", opts);
                    return true;
                }
            }

        };

        $(function () {
            selectCount = $.getUrlParam("selectCount");
            if (typeof selectCount === "undefined" || selectCount == null)
                selectCount = -1;
            page_Init();
            InitList();
        });
        function page_Init() {
            $("body").css("overflow", "hidden");
        }
        function btnSearch_Click() {
            InitList();
        }
        function btnSelected_Click() {
            flexiSelect();
        }

        function DoAction(i, v) {
            var arr = new Array();
            arr.push(i);
            arr.push(v);
            returnParent(arr);
        }
        function InitList(postUrl) {
            opts.para["funName"] = $("#txtFunName").val();
            opts.para["funType"] = $("#ddlFunType").val();
            if (typeof (postUrl) == "undefined" || postUrl.length == 0) {
                postUrl = "/Function/GetList";
            }
            opts.url = postUrl;
            $("#DataGrid").dg(opts);
        }
        function flexiSelect() {
            if (retArr.length < 1) {
                alert('请选择一条数据!');
                return false;
            }
            if (selectCount > -1 && retArr.length > selectCount) {
                alert("只可选择 " + selectCount + " 个，请检查选择项。");
                return false;
            }
            returnParent(retArr);
            return false;
        }
    </script>
}
<div style="height: 470px; padding-left: 5px; padding-right: 5px; overflow: hidden;
    overflow-y: auto;">
    @{
        // 渲染输出列表
        var dataSearch = new ViewDataDictionary();
        dataSearch.Add("PanelTitle", "函数搜索");
        @Html.Partial("_SearchTitlePanel", dataSearch);
        //Html.RenderPartial("_SearchTitlePanel", dataSearch);
    }
    @Html.Partial("_SearchPanel")
    @Html.Partial("_SelectedPanel")
    @{
        // 渲染输出列表
        var dataGrid = new ViewDataDictionary();
        dataGrid.Add("PanelTitle", "函数列表");
        dataGrid.Add("GridID", "DataGrid");
        dataGrid.Add("ShowPager", true);
        dataGrid.Add("ShowLoading", true);
        @Html.Partial("_GridPanel", dataGrid);
    }
</div>
